package com.han.cloud.service;

import com.han.cloud.dto.TradeDTO;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author hanky
 * @date 2021/11/12
 */
@Service
@Slf4j
public class PaymentService {

    @HystrixCommand(fallbackMethod = "getTradeHandler", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
    })
    public TradeDTO getTrade1(String id){
        TradeDTO res = new TradeDTO();
//        try {
//            TimeUnit.SECONDS.sleep(3);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println(1/0);
        System.out.println("1111111");
        res.setId(id);
        res.setTradeNo("111111");
        return res;
    }

    public TradeDTO getTrade2(String id){
        TradeDTO res = new TradeDTO();
        res.setId(id);
        res.setTradeNo("222222");
        System.out.println("2222222");
        return res;
    }

    public TradeDTO getTradeHandler(String id){
        TradeDTO res = new TradeDTO();
        res.setTradeNo("sb");
        res.setId(id);
        return res;
    }
}
